import datetime, logging
import settings
from google.appengine.ext import db
from google.appengine.api import users

class User(db.Model):
    """contains profile settings of the user"""
    user = db.UserProperty()
    location = db.GeoPtProperty(default=db.GeoPt(29.986707, 31.438864)) # default location of the user
    private = db.BooleanProperty(default=True) # default privacy setting for created POIs
    @staticmethod
    def get_current_user():
        try:
            user = User.gql("WHERE user = :1", users.get_current_user()).get()
        except db.KindError:
            user = User(user=users.get_current_user())
            user.put()
        if not(user):
            user = User(user=users.get_current_user())
            user.put()
        return user    

class POI(db.Model):
    user = db.ReferenceProperty(User)
    lat_lng = db.GeoPtProperty(required=True)
    private = db.BooleanProperty(required=True)
    tags = db.ListProperty(db.Key,default=[])
    comments = db.ListProperty(db.Key,default=[])
    title = db.StringProperty(required=True)
    desc1 = db.StringProperty(default="")
    desc2 = db.StringProperty(default="")
    desc3 = db.StringProperty(default="")
    
class Tag(db.Model):
    name = db.CategoryProperty()
    
    
class Comment(db.Model):
    comment = db.TextProperty(required=True)
    user = db.ReferenceProperty(User)
